package org.jeecg.modules.demo.com.kunpeng.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.com.kunpeng.service.ISaleContractDetailService;
import org.jeecg.modules.demo.com.kunpeng.entity.SaleContractDetail;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceCode;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceException;
import org.jeecg.modules.demo.com.kunpeng.mapper.SaleContractDetailMapper;
import org.jeecg.modules.demo.com.kunpeng.vo.SaleContractDetailVO;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 销售合同详情
 * @Author: jeecg-boot
 * @Date:   2022-12-03
 * @Version: V1.0
 */
@Service
@Slf4j
public class SaleContractDetailServiceImpl extends ServiceImpl<SaleContractDetailMapper, SaleContractDetail> implements ISaleContractDetailService {
	
	@Autowired
	private SaleContractDetailMapper saleContractDetailMapper;

	/**
	 * 根据销售合同表id查询合同详情表数据
	 * @param mainId 主表id
	 * @return
	 */
	@Override
	public List<SaleContractDetail> selectByMainId(String mainId) {
		return saleContractDetailMapper.selectByMainId(mainId);
	}

	/**
	 * 根据id查询销售合同表详情
	 * @param id
	 * @return
	 */
	@Override
	public SaleContractDetailVO selectById(String id) {
		log.info("开始处理根据id查询项目详情：service");
		SaleContractDetailVO saleContractDetailVO = saleContractDetailMapper.selectById(id);
		if(saleContractDetailVO==null){
			String message="数据不存在，请联系管理员！";
			throw new ServiceException(ServiceCode.ERR_NOT_FOUND,message);
		}
		return saleContractDetailVO;
	}

	/**
	 * 根据项目编号获取项目金额
	 * @param projectId
	 * @return
	 */
	@Override
	public SaleContractDetailVO selectProjectAmountByProjectId(String projectId) {
		SaleContractDetailVO saleContractDetailVO = saleContractDetailMapper.selectProjectAmountByProjectId(projectId);
		return saleContractDetailVO;
	}

	@Override
	public void insert(SaleContractDetail saleContractDetail) {
		saleContractDetailMapper.insert(saleContractDetail);
	}
}
